<?php
class Pms extends Admin_Controller
{
	function __construct()
	{
		parent::__construct();
	}
	
	function form($id=FALSE){
		$data['pm'] = new Pm($id);
		$data['attachs'] = new Attach_file();
		$data['attachs']->where("content_id = ".$id." and module = 'pms'")->get();
		$this->template->build('admin/pm_form',$data);
	}
	
	function save($id=FALSE){
		if($_POST){
			$pm = new Pm($id);
			if(!$id)$_POST['user_id'] = $this->session->userdata('id');
			$pm->from_array($_POST);
			$pm->save();
			
			$id = $pm->id;
			$pm->clear();
			
			foreach($_POST['file'] as $key=>$item){
				if($item){
					$attach = new Attach_file();
					$attach->from_array(array('content_id' => $id,'module'=>'pms','file_name'=>$_POST['file_name'][$key],'file'=>$item));
					$attach->save();
				}
			}
			
			set_notify('success', lang('save_data_complete'));
		}
		redirect('pms/admin/pms/form/'.$_POST['id']);
	}
	
	function network_list(){
		$pm_network = new Pm_network_province();
		$data['network'] = $pm_network->order_by('province_name , district_name','asc')->get_page();		
		$this->template->build('admin/pms_network_index',$data);
	}
	
	function network_form($id=FALSE){
		$data['network'] = new Pm_network_province($id);
		$this->template->append_metadata(js_datepicker());
		$this->template->build('admin/pms_network_form',$data);
	}
	
	function network_save($id=FALSE){
		$pm = new Pm_network_province($id);
		$_POST['user_id'] = $this->session->userdata('id');
		$_POST['info_date'] = Date2DB($_POST['info_date']);
		$pm->from_array($_POST);
		$pm->save();
		set_notify('success', lang('save_data_complete'));
		redirect($_POST['referer']);
	}
	
	function network_delete($id){
		$pm = new Pm_network_province($id);
		$pm->delete();
		set_notify('success', lang('delete_data_complete'));
		redirect('pms/admin/pms/network_list');
	}
}
?>